mk = angular.module("myapp",[]);
mk.service('crsj',function(){
  this.cr = function(dataObj){
    if(dataObj){
      dataStr = JSON.stringify(dataObj);
      localStorage.setItem('ly',dataStr)
    }else {
      localStorage.setItem('ly','{"info":[]}');
    }
  }
  this.qu = function(){
    dataStr = localStorage.getItem('ly');
    if (dataStr) {
      dataObj = JSON.parse(dataStr);
      return dataObj;
    }
  }
})

mk.controller('tjsj',['$scope','crsj',function($scope,crsj){
  if (crsj.qu()) {
    $scope.zhi = crsj.qu().info
  }else {
    crsj.cr();
  }

  $scope.add = function(index){
    dataObj = crsj.qu();
    dataObj.info.push({"title":$scope.title,"content":$scope.content});
    $scope.zhi = dataObj.info;
    crsj.cr(dataObj)
  }
  $scope.del = function(index){
    dataObj = crsj.qu();
    dataObj.info.splice(index,1);
    $scope.zhi = dataObj.info;
    crsj.cr(dataObj);
  }
}])
